在 YAML 文件中用 number_sections: TRUE 参数设置自动编号:

1 Title

1.1 A subtitle

1.2 Another subtitle

2 Another title

可以用 html 中的 <br> 标签来插入换行符。

A first sentence



A seconde sentence

同样可以用 html 代码居中图片

FigName

有时候 R 代码生成的图片周围有太多空白,这时可以用 fig.asp 参数来调整

library(png)
library(grid)
img <- readPNG("Snipaste_2020-03-04_20-36-21.png")
grid.raster(img)

添加 footer 和 header 我们也可以在文档的开头或结尾添加一些 html 代码

在标题前加上空行 除了在每个标题前加上 <br> 外,更方便的办法是直接在 .css 文件中添加样式。创建一个 style.css 文件

A title will follow, but with a lot of space before it

3 Title 1

content of part 1

4 Title 2

content of part 2

可以在代码块的 header 中添加图注


library(tidyverse)
mpg %>%
  ggplot( aes(x=reorder(class, hwy), y=hwy, fill=class)) + 
    geom_boxplot() +
    xlab("class") +
    theme(legend.position="none")
Figure: Here is a really important caption.

Figure: Here is a really important caption.

在 R Markdown 中可以用 LaTeX 语法插入数学公式,用 $ 分隔 Latex 语法:

$A = (r^{4}) / $

并排放两张图

boxplot(1:10)
plot(rnorm(10))

为子标题实现选项卡切换的效果

5 Use buttons or tabs for sub-chapters


Save space in your document using buttons or tabs for sub chapters. Add this code at the end of your title:

5.1 First

A first section

5.2 Second

content of sub-chapter #2

5.3 Third

content of sub-chapter #3

用 DT 包来展示表格

library(DT)
datatable(mtcars, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T) )

隐藏代码

高亮一段话

  • This is my first conclusion
  • This is my second conclusion

视差滚动

内部链接 http://tholman.com/github-corners/

第一步 - 在标题处添加一个锚点:


A work by Yan Holtz

Yan.holtz.data@gmail.com